package JDBC.Deno05;

import org.apache.commons.dbcp.BasicDataSourceFactory;

import javax.sql.DataSource;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.Statement;
import java.util.Properties;

public class Demo {
    public static void main(String[] args) throws Exception {
        //1.  引入jar文件
        //2.  将配置文件 properties 文件 放到src下
        //3.  将 properties 文件转换为 Properties对象
        Properties ppt = new Properties();
        //获取当前文件夹下的 properties 文件
        InputStream is = Demo.class.getClassLoader().getResourceAsStream("dbcp.properties");
        //加载
        ppt.load(is);
        //4.  通过连接池的工厂类。创建连接池
        DataSource dataSource = BasicDataSourceFactory.createDataSource(ppt);
        //5.  从池中获取一个连接
        Connection conn = dataSource.getConnection();
        Statement state = conn.createStatement();
        state.execute("insert into xzk_user values('张三','lisi',110)");
        state.close();
        conn.close();

    }
}
